package com.ruoyi.common.enums.wecom;


import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomMsgCallBackExternalContactChangeTypeEnum {

    ADD_EXTERNAL_CONTACT("add_external_contact", "添加企业客户事件"),
    EDIT_EXTERNAL_CONTACT("edit_external_contact", "编辑企业客户事件"),
    ADD_HALF_EXTERNAL_CONTACT("add_half_external_contact", "外部联系人免验证添加成员事件"),
    DEL_EXTERNAL_CONTACT("del_external_contact", "删除企业客户事件"),
    DEL_FOLLOW_USER("del_follow_user", "删除跟进成员事件"),
    TRANSFER_FAIL("transfer_fail", "客户接替失败事件"),
    MSG_AUDIT_APPROVED("msg_audit_approved", "客户同意进行聊天内容存档事件回调"),


    ;

    private final String code;
    private final String desc;


    private static final Map<String, WecomMsgCallBackExternalContactChangeTypeEnum> ENUM_MAP;

    static {
        WecomMsgCallBackExternalContactChangeTypeEnum[] values = values();
        Map<String, WecomMsgCallBackExternalContactChangeTypeEnum> enToCn = new HashMap<>(values.length);
        for (WecomMsgCallBackExternalContactChangeTypeEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomMsgCallBackExternalContactChangeTypeEnum getEnumByType(String type) {
        WecomMsgCallBackExternalContactChangeTypeEnum wecomMsgCallBackExternalContactChangeTypeEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomMsgCallBackExternalContactChangeTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomMsgCallBackExternalContactChangeTypeEnum;
    }


}
